<template>
    <Wrapper :tab="'/setting/weChat'">
        <div class="weChat">
            <div class="info">
                <div class="data flex">
                    <div class="box flex" v-for="item in data" :key="item.title">
                        <div class="title">{{ item.title }}:</div>
                        <div class="num">&nbsp;&nbsp;{{ item.num }}</div>
                    </div>
                </div>
                <div>
                    <a-button type="primary" ghost>待验证企微号</a-button>
                </div>
            </div>
            <div class="card">
                <Grouping class="grouping" :data="arr" :config="config" />
                <a-table
                    class="card-table"
                    :columns="columns"
                    :data-source="list"
                    :row-selection="{selectedRowKeys: state.selectedRowKeys, onChange: handleSelectChange}"
                    :rowKey="record => JSON.stringify(record)"
                    :pagination="{
                        showQuickJumper: true,
                        showSizeChanger: false,
                    }"
                >
                    <template #bodyCell="{column, text}">
                        <template v-if="column.dataIndex === 'name'">
                            <a>{{ text }}</a>
                        </template>

                        <template v-if="['status', 'port', 'manager'].includes(column.dataIndex)">
                            <a-tag>{{ text }}</a-tag>
                        </template>
                    </template>
                    <template #title>
                        <div class="flex-jsb">
                            <div class="flex">
                                <a-button type="primary" ghost :icon="h(PlusOutlined)" @click="handleAddWeChat">
                                    企微号
                                </a-button>
                                <a-select class="select" placeholder="Jack">
                                    <a-select-option value="jack">Jack</a-select-option>
                                    <a-select-option value="lucy">Lucy</a-select-option>
                                    <a-select-option value="disabled">Disabled</a-select-option>
                                    <a-select-option value="Yiminghe">yiminghe</a-select-option>
                                </a-select>
                                <a-select class="select" placeholder="选择企业">
                                    <a-select-option value="jack">Jack</a-select-option>
                                    <a-select-option value="lucy">Lucy</a-select-option>
                                    <a-select-option value="disabled">Disabled</a-select-option>
                                    <a-select-option value="Yiminghe">yiminghe</a-select-option>
                                </a-select>
                                <Search placeholder="搜索企微号" />
                                <a-select class="select" placeholder="端口">
                                    <a-select-option value="jack">Jack</a-select-option>
                                    <a-select-option value="Yiminghe">yiminghe</a-select-option>
                                </a-select>
                            </div>
                            <div class="flex right">
                                <a-button>分组</a-button>
                                <a-button class="ml12" type="primary" :icon="h(DownloadOutlined)"> 导出数据 </a-button>
                            </div>
                        </div>
                    </template>
                </a-table>
            </div>
        </div>
        <WeChatModal ref="loginRef" />
    </Wrapper>
</template>

<script setup lang="ts">
import {h, ref, reactive} from "vue";
import {PlusOutlined, DownloadOutlined} from "@ant-design/icons-vue";
import {Grouping, Search} from "@/components";
import Wrapper from "./components/Wrapper.vue";
import WeChatModal from "./components/WeChatModal.vue";

const loginRef = ref<any>();

const state = reactive({
    selectedRowKeys: [],
});

const handleSelectChange = chooseRow => {
    console.log("selectedRowKeys", chooseRow);
    state.selectedRowKeys = chooseRow;
};

const data = [
    {
        title: "套餐总席位",
        num: 123,
    },
    {
        title: "总在线",
        num: 123,
    },
    {
        title: "此账号可用席位",
        num: "不限",
    },
    {
        title: "此账号在线席位",
        num: 123,
    },
];

const columns = [
    {
        title: "企微号",
        dataIndex: "weChat",
    },
    {
        title: "员工编号",
        dataIndex: "number",
    },
    {
        title: "分组",
        dataIndex: "name",
    },
    {
        title: "状态",
        dataIndex: "status",
    },
    {
        title: "客户数/群数",
        dataIndex: "count",
    },
    {
        title: "端口",
        dataIndex: "port",
    },
    {
        title: "管理员工",
        dataIndex: "manager",
    },
    {
        title: "操作",
        dataIndex: "action",
    },
];

const config = {
    title: "title",
    key: "key",
    num: "num",
};

const arr = new Array(1).fill(1).map((item, index) => ({title: `分组${index + 1}`, num: 123, key: index}));

const list = new Array(4).fill(0).map((item, index) => ({
    name: "测试",
    weChat: "测试" + index,
    number: "1234567890" + index,
    status: 1,
    count: "123/456",
    port: 1,
    manager: "测试" + index,
}));

// 添加企微号
const handleAddWeChat = () => {
    loginRef.value.show();
};
</script>
<style scoped lang="less">
.weChat {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    .info {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        background: #fff;
        border-radius: 4px;
        padding: 12px;
        margin-bottom: 20px;
        .data {
            .box {
                margin-left: 32px;
                &:first-child {
                    margin-left: 0;
                }
                .title {
                    font-size: 14px;
                    font-weight: 400;
                    color: rgba(0, 0, 0, 0.45);
                }
                .num {
                    font-weight: 600;
                    color: rgba(0, 0, 0, 0.85);
                }
            }
        }
    }
    .card {
        height: 100%;
        overflow: hidden;
        padding: 0;
        margin-top: 0;
        height: 100%;
        border-radius: 4px;
        overflow: hidden;
        display: flex;
        background-color: #fff;
        > div {
            height: 100%;
            overflow: hidden;
        }

        .grouping {
            margin-right: 12px;
            border-right: 1px solid #ccc;
        }
    }
    .card-table {
        border-radius: 4px;
        flex: 1;
        background: #fff;
        :deep(.ant-table-title) {
            padding: 10px;
        }
        :deep(.ant-spin-nested-loading),
        :deep(.ant-spin-container) {
            height: 100%;
            display: flex;
            flex-direction: column;
            .ant-table {
                flex: 1;
            }
        }
        :deep(.ant-table-pagination) {
            display: flex;
            justify-content: center;
        }

        .select {
            width: 120px;
            margin-left: 12px;
        }
        .search {
            width: 200px;
            margin-left: 12px;
        }
    }
}
</style>
